import 'package:common_utils/common_utils.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:testlzhu/bean/loginbean_entity.dart';
import 'package:testlzhu/common/login/login_utils.dart';
import 'package:testlzhu/data/net/http_manager.dart';
import 'package:testlzhu/page/basemian/base_main_view.dart';
import 'package:testlzhu/page/login/logig_state.dart';
import 'package:testlzhu/utils/toast_show.dart';

class LoginLogic extends GetxController {
  final LoginState state = LoginState();

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
    EasyLoading.dismiss();
  }

  //是否显示密码
  bool visi = false;

  void setVis() {
    visi = !visi;
    update();
  }

  bool isPhone = false;

  void setPhotnTip(bool tip) {
    isPhone = tip;
    update();
  }

  void login() {
    var map = <String, String>{};
    EasyLoading.show(status: "asdasd");
    map['mobile'] = state.account;
    map['password'] = state.pass;
    HttpManager().post<LoginbeanEntity>(
        url: 'index/login',
        data: map,
        success: (success) {
          LogUtil.e(success.userinfo?.nickname);
          EasyLoading.dismiss();
          LoginUtils.init().backLoginData(success.userinfo);
          Get.offAll(const BasePage());
        },
        error: (error) {
          ToastShow.showToast(error.message);
          EasyLoading.dismiss();
        });
  }
}
